package model;

import java.awt.Color;
import java.util.*;


public class RoffPolygon3D {

    RoffVector3D normal;
    int[] vertexIndices;
    Color baseColor;

    public RoffPolygon3D() {
        baseColor = new Color(150,150,150);
    }

    public RoffPolygon3D(String stringVersion) {

        StringTokenizer st = new StringTokenizer(stringVersion);

        try {
            int numPoints = Integer.parseInt(st.nextToken());

            vertexIndices = new int[numPoints];

            for (int i = 0; i < numPoints; i++) {
                vertexIndices[i] = Integer.parseInt(st.nextToken());
            }
        } catch (NumberFormatException e) {
        	e.printStackTrace(); 
        } catch (NoSuchElementException ee) {
        	ee.printStackTrace(); 
        }
        baseColor = new Color(150,150,150);
    }


    public int getNumEdges() {
        return vertexIndices.length;
    }

    public RoffPolygonEdge getEdge(int index) {

        int secondEnd = index + 1;
        if (index == vertexIndices.length - 1) {
            secondEnd = 0;
        }
        return new RoffPolygonEdge(vertexIndices[index], vertexIndices[secondEnd]);
    }

    public int getVertex(int index){
        return vertexIndices[index];
    }

    public String toString() {
        String rval = String.valueOf(vertexIndices.length);
        for (int i = 0;i < vertexIndices.length;i++) {
            rval = rval + " " + vertexIndices[i];
        }        
        return rval;
    }
}